package com.login_php.initialization;

import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.login_php.constants.SessionConstants;
import com.login_php.manager.AplicationEng;

public class AplicationInitializeSessionListener implements HttpSessionListener{

	@Override
	public void sessionCreated(HttpSessionEvent event) {
	
		final HttpSession session = event.getSession();
    	final ServletContext context = session.getServletContext();
    	context.setAttribute(session.getId(), session);
    	session.setAttribute(SessionConstants.ENG_KEY, AplicationEng.initialize());
	
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		final HttpSession session = event.getSession();
    	final ServletContext context = session.getServletContext();
    	context.removeAttribute(session.getId());
	}

}
